<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller {
	private $pageData=array();
	private $siteData=array();
	private $tableName;
	public function __construct(){
		parent::__construct();
		//连接数据库
		$this->db = $this->load->database ( "default", TRUE );
		//读取dilicms的配置属性
		$this->siteData = $this->db->get($this->db->dbprefix('site_settings'))->row_array();
		$this->tableName=$this->db->dbprefix('u_m_content');
	}
	
	public function index()
	{
		$this->pageData["Links"]=$this->__getLinks();
		$this->pageData["tzgg"]=$this->__getAbstractData();
		$this->pageData["zxyw"]=$this->__getAbstractData(12,2);
		$this->pageData["focus"]=$this->__getFocus();
		$this->pageData["achieve"]=$this->__getAchieve();
		$this->load->view('home',$this->pageData);
	}
	
	//获取友情链接
	private function __getLinks(){
		$maxNums=6;
		$sql="SELECT links_name,links_url FROM dili_u_m_links limit 0,{$maxNums};";
		$arr=$this->db->query($sql)->result_array();
		return $arr;
	}
	
	//获取焦点图
	private function __getFocus(){
		$maxNums=5;
		$sql="SELECT focus,title FROM dili_u_m_focus order by id desc limit 0,{$maxNums};";
		$focus=$this->db->query($sql)->result_array();
		return $focus;
	}
	
	//获取科研成果信息
	private function __getAchieve(){
		$maxNums=10;
		$sql="SELECT pic,name FROM dili_u_m_achieve order by id desc limit 0,{$maxNums};";
		$achieve=$this->db->query($sql)->result_array();
		return $achieve;
	}
	
	//获取新闻列表
	private function __getAbstractData($_id=26,$_rows=5){
		$whereCondition="where ";
		$whereCondition.=($_id!=0)?("category_name={$_id}"):("1=1");
		$sql="select id,title,create_time,content,focus from {$this->tableName} {$whereCondition}";
		$sql.=" order by id desc limit 0,{$_rows}";
		$resData=$this->db->query($sql)->result_array();
		return $resData;
	}
}
